<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>卡列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>

    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="../../resource/css/plugins/morris/morris-0.4.3.min.css"
          th:href="@{/resource/css/plugins/morris/morris-0.4.3.min.css}" rel="stylesheet">

    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">

    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>

    <link href="../../resource/hotui/css/switchery.min.css"
          th:href="@{/resource/hotui/css/switchery.min.css}" rel="stylesheet"/>

    <link href="../../resource/lib/bootstrap-daterangepicker/daterangepicker.min.css"
          th:href="@{/resource/lib/bootstrap-daterangepicker/daterangepicker.min.css}" rel="stylesheet">

    <link href="../../resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
          th:href="@{/resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css}" rel="stylesheet"/>

    <link href="../../resource/hotui/css/awesome-bootstrap-checkbox.min.css"
          th:href="@{/resource/hotui/css/awesome-bootstrap-checkbox.min.css}"
          rel="stylesheet">


    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .nav-tabs input {
            width: 20px;
            height: 23px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <input type="hidden" th:value="*{status}"/>
                            <input type="hidden" th:value="*{voltageStatus}"/>
                            <div class="form-group m-r-sm">
                                <label class="control-label">卡号：</label>
                                <input type="text" class="form-control input-sm mb10" id="cardNo" name="cardNo"
                                       th:value="*{cardNo}"
                                       placeholder="请输入完整卡号"/>
                                <label class="control-label">卡类型：</label>
                                <select class="form-control" name="type" id="type">
                                    <option value="-1">全部</option>
                                    <option th:selected="*{type==0}" value="0">报警工卡</option>
                                    <option th:selected="*{type==1}" value="1">报警按钮</option>
                                    <option th:selected="*{type==2}" value="2">成人腕带</option>
                                </select>
                            </div>
                            <div style="float: right;">
                                <button type="button" class="btn btn-success" onclick="jsHelper.search()">筛选</button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.searchAll()">显示全部
                                </button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.setCard()">添加</button>
                                <button type="button" onclick="jsHelper.uploadUpdateExcelModal()"
                                        class="btn btn-success">导入
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"
                            th:class="${(condition.status==null&&condition.voltageStatus==null)?'active':''}">
                            <a th:href="@{/equipment/card/list}" href="#tab-2">全部</a>
                        </li>
                        <li th:class="${condition.status==true?'active':''}">
                            <a th:href="@{/equipment/card/list(status=true)}">
                                报警</a>
                        </li>
                        <li th:class="${condition.voltageStatus==1?'active':''}">
                            <a th:href="@{/equipment/card/list(voltageStatus=1)}">
                                低电压</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <table class="table table-bordered table-hover table-center">
                                    <tr>
                                        <th>序号</th>
                                        <th>卡编号</th>
                                        <th>卡类型</th>
                                        <th>卡版本</th>
                                        <th>报警状态</th>
                                        <th>电压状态</th>
                                        <th>冻结状态</th>
                                        <th>注销状态</th>
                                        <th>操作</th>
                                    </tr>
                                    <tr th:each="card,index:${cards}">
                                        <td th:text="${index.index+1}"></td>
                                        <td th:text="${card.cardNo}"></td>
                                        <td>
                                            <span th:text="${card.type.desc}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${card.version}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${card.getStatusStyle()}"
                                                  th:text="${card.status?'报警':'未报警'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${card.getVoltageStatusStyle()}"
                                                  th:text="${card.voltageStatus.desc}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${card.getEnableStyle()}"
                                                  th:text="${card.enable?'正常':'冻结'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${card.getDeleteStyle()}"
                                                  th:text="${card.deleteStatus?'注销':'正常'}"></span>
                                        </td>
                                        <td>
                                            <button th:onclick="jsHelper.setCard([[${card.cardId}]],[[${card.cardNo}]],[[${card.type.code}]],[[${card.version}]])"
                                                    type="button"
                                                    class="btn btn-info btn-xs m-b-none">编辑
                                            </button>
                                            <button onclick="jsHelper.setEnable(1)"
                                                    th:onclick="|jsHelper.setEnable(${card.cardId})|" type="button"
                                                    class="btn btn-info btn-xs m-b-none"
                                                    th:class="${card.enable?'btn btn-danger btn-xs m-b-none':'btn btn-info btn-xs m-b-none'}"
                                                    th:text="${card.enable?'冻结':'启用'}">
                                            </button>
                                            <button th:if="${!card.deleteStatus}" onclick="jsHelper.setDeleteStatus(1)"
                                                    th:onclick="|jsHelper.setDeleteStatus(${card.cardId})|"
                                                    type="button"
                                                    class="btn btn-danger btn-xs m-b-none"> 注销
                                            </button>
                                        </td>
                                    </tr>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="set_card_modal" class="modal-content-tag">
    <form id="cardModelForm">
        <div class="form-group">
            <label class="col-sm-4 control-label">卡号：</label>
            <div class="col-sm-8">
                <input id="cardModelId" name="cardModelId" minlength="2" type="hidden" class="form-control"
                       value="0">
                <input id="cardModelNo" type="text" class="form-control" name="cardModelNo">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">卡版本：</label>
            <div class="col-sm-8">
                <input id="cardModelVersion" type="text" class="form-control" name="cardModelVersion">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">卡类型：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" name="cardModelType" id="cardModelType">
                    <option value="0">报警工卡</option>
                    <option value="1">报警按钮</option>
                    <option value="2">成人腕带</option>
                </select>
            </div>
        </div>
    </form>
</div>

<div id="uploadExcel_modal" class="modal-content-tag">
    <div class="form-horizontal" style="width: 479px;">
        <div class="form-group form-inline">
            <label class="col-sm-4 control-label">选择excel：</label>
            <div class="col-sm-8">
                <button class="btn btn-success  dim" type="button" onclick="javascript:$('#updateFile').click()"><i
                        class="fa fa-upload">选择文件</i>
                </button>
                <span class="col-sm-8" style="display: none">文件名称</span>
                <input type="file" name="updateFile" id="updateFile" accept="application/vnd.ms-excel" required
                       style="display: none">
            </div>
        </div>
    </div>
</div>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js" th:src="@{/resource/js/jquery.min.js?20190316}"></script>
<script src="../../resource/js/bootstrap.min.js" th:src="@{/resource/js/bootstrap.min.js?20190316}"></script>

<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316?1234567"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316(123)}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/hotui/js/plugins/datetimepick/js/moment.min.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/moment.min.js}"></script>

<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script src="../../resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>

<script src="../../resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js}"></script>


<script src="../../resource/js/switchery.min.js" th:src="@{/resource/js/switchery.min.js}"></script>

<script src="../../resource/js/plugins/validate/jquery.validate.min.js"
        th:src="@{/resource/js/plugins/validate/jquery.validate.min.js}"></script>

<script src="../../resource/js/plugins/validate/messages_zh.min.js"
        th:src="@{/resource/js/plugins/validate/messages_zh.min.js}"></script>

<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>

<script src="../../resource/hotui/plugins/zyUpload/core/zyFile.js"></script>
<script src="../../resource/hotui/plugins/zyUpload/control/js/zyUpload.js"></script>
<script src="../../resource/hotui/js/plugins/ajaxfileupload.js"
        th:src="@{/resource/hotui/js/plugins/ajaxfileupload.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/equipment/card/list}]]*/  "";
    const equipmentApiBase = /*[[@{/equipment}]]*/  "/equipment";
</script>

<script>
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            jsHelper.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $(".searchBtn").trigger("click");
            }
        });

        $("input[name=chkAll]").change(function () {
            if ($(this).prop("checked")) {
                $("input[name=chkUser]").prop("checked", "checked");
            } else {
                $("input[name=chkUser]").removeAttr("checked");
            }
        });
        jsHelper.init()

        // setInterval(function () {
        //     jsHelper.search($("input[name=pageIndex]").val());
        // }, 300000);
    });

    var setCardModel = $("#set_card_modal").modal("卡详情", function () {
        $("#cardModelForm").submit();
    });

    var uploadExcelModal = $("#uploadExcel_modal").modal("报警工卡excel导入", function () {
        jsHelper.uploadExcel();
    });

    var jsHelper = {
        init: function () {
        },
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        uploadUpdateExcelModal: function () {
            uploadExcelModal.show(function () {
                $("#updateFile").change(function () {
                    $("#updateFile").prev().css("display", "");
                    var filePath = $("#updateFile").val().split("\\");
                    $("#updateFile").prev().text(filePath[filePath.length - 1]);
                })
            });
        },
        uploadExcel: function () {
            hot.managerFileUpload(equipmentApiBase + "/lead/card", "updateFile", null, function (data) {
                if (data == 1) {
                    window.location.reload();
                }
            });
        },
        /**
         * 修改状态
         * @param dataId
         */
        setEnable: function (dataId) {
            hot.ajax("/equipment/edit/card/enable", {
                cardId: dataId
            }, function (ret) {
                if (ret.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                }
                else {
                    hot.tip.error("操作失败-" + ret.resultMsg);
                }
            }, function () {
            }, "post");
        },
        /**
         * 修改状态
         * @param dataId
         */
        setDeleteStatus: function (dataId) {
            hot.confirm("确定注销该卡吗？", function () {
                hot.ajax("/equipment/delete/card", {
                    cardId: dataId
                }, function (ret) {
                    if (ret.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        })
                    }
                    else {
                        hot.tip.error("操作失败-" + ret.resultMsg);
                    }
                }, function () {
                }, "post");
            });
        },
        setCard: function (cardId, cardNo, cardType, version) {
            setCardModel.show(function () {
                if (cardId != null) {
                    $("#cardModelId").val(cardId);
                    $("#cardModelNo").val(cardNo);
                    $("#cardModelType").val(cardType);
                    $("#cardModelVersion").val(version);
                }
                $("#cardModelForm").validateCallback(function () {
                    var requestData = {
                        cardId: $("#cardModelId").val(),
                        cardNo: $("#cardModelNo").val(),
                        type: $("#cardModelType").val(),
                        version: $("#cardModelVersion").val(),
                    };

                    hot.ajax(equipmentApiBase + "/ajax/save/card", requestData, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            setCardModel.hide(function () {
                                hot.tip.success("设置成功");
                                window.location.reload();
                            });
                        } else {
                            hot.tip.error("设置失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                })
            });
        },
    };
</script>
</body>
</html>
